import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class jdbcDelete {
    public  void run() throws SQLException, ClassNotFoundException {
        // ---------------------Begin------------------------
        //获取数据库连接
        Connection conn = getConnection();

        //获取statement对象
        Statement stmt = conn.createStatement();

        //删除staff员工表中id为4的记录
        String sql = "DELETE FROM staff WHERE id = '4'";
        stmt.executeUpdate(sql);

        //关闭数据库连接，释放资源
        stmt.close();
        conn.close();

        // ---------------------End------------------------
    }
    public Connection getConnection() throws ClassNotFoundException, SQLException {
        // ---------------------Begin------------------------
        //获取数据库连接，账户名：root,密码：123123, 数据库名：company,MySQL版本为8.0.20
        Class.forName("com.mysql.cj.jdbc.Driver");
        String username = "root";
        String password = "123123";
        String url = "jdbc:mysql://localhost:3306/company?serverTimezone=UTC&useSSL=false";
        return DriverManager.getConnection(url, username, password);
        // ---------------------End------------------------
    }

}
